package com.zh.kotlin_mvvm.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.zh.kotlin_mvvm.R;
import com.zh.kotlin_mvvm.view.RoundProgressBar;

public class ProgressActivity extends AppCompatActivity {

    private RoundProgressBar roundProgressBar;
    private RoundProgressBar roundProgressBar2;
    private RoundProgressBar roundProgressBar3;
    private RoundProgressBar roundProgressBar4;
    private RoundProgressBar roundProgressBar5;
    private RoundProgressBar roundProgressBar6;
    private RoundProgressBar roundProgressBar7;
    private int progress = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_progress);

        LinearLayout parent = new LinearLayout(this);
        parent.setOrientation(LinearLayout.VERTICAL);
        parent.setBackgroundColor(0xffffffff);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(-2, -2);
        Button button = new Button(this);
        button.setText("开始圆形进度");
        parent.addView(button, lp);

        LinearLayout roundLayout = new LinearLayout(this);
        roundLayout.setOrientation(LinearLayout.HORIZONTAL);
        lp = new LinearLayout.LayoutParams(-2, -2);
        parent.addView(roundLayout, lp);
        roundProgressBar = new RoundProgressBar(this);
        roundProgressBar.setStyle(RoundProgressBar.FILL_UP);//设置进度风格 0空心，1实心，2实心从下到上
        roundProgressBar.setTextColor(0xffffffff);//设置中间进度百分比的字符串的颜色
        lp = new LinearLayout.LayoutParams(160, 160);
        lp.setMargins(5, 5, 5, 5);
        roundLayout.addView(roundProgressBar, lp);

        roundProgressBar2 = new RoundProgressBar(this);
        lp = new LinearLayout.LayoutParams(160, 160);
        lp.setMargins(5, 5, 5, 5);
        roundLayout.addView(roundProgressBar2, lp);

        roundProgressBar3 = new RoundProgressBar(this);
        roundProgressBar3.setCircleColor(0xffD1D1D1);//设置圆环的颜色
        roundProgressBar3.setCircleProgressColor(0xff000000);//设置圆环进度的颜色
        roundProgressBar3.setTextColor(0xff9A32CD);//设置中间进度百分比的字符串的颜色
        roundProgressBar3.setRoundWidth(10);//设置圆环的宽度
        roundProgressBar3.setTextSize(18);//设置中间进度百分比的字符串的字体大小
        lp = new LinearLayout.LayoutParams(160, 160);
        lp.setMargins(5, 5, 5, 5);
        roundLayout.addView(roundProgressBar3, lp);

        LinearLayout roundLayout2 = new LinearLayout(this);
        roundLayout2.setOrientation(LinearLayout.HORIZONTAL);
        lp = new LinearLayout.LayoutParams(-2, -2);
        parent.addView(roundLayout2, lp);

        roundProgressBar4 = new RoundProgressBar(this);
        roundProgressBar4.setCircleColor(0xffC6E2FF);
        roundProgressBar4.setCircleProgressColor(0xffCD3333);
        roundProgressBar4.setRoundWidth(10);
        roundProgressBar4.setTextIsDisplayable(false);//设置是否显示数字百分比
        lp = new LinearLayout.LayoutParams(160, 160);
        lp.setMargins(5, 5, 5, 5);
        roundLayout2.addView(roundProgressBar4, lp);

        roundProgressBar5 = new RoundProgressBar(this);
        roundProgressBar5.setStyle(RoundProgressBar.FILL);
        roundProgressBar5.setCircleProgressColor(0xffC2C2C2);
        roundProgressBar5.setRoundWidth(1);
        roundProgressBar5.setCircleColor(0xffff0000);
        roundProgressBar5.setTextIsDisplayable(false);
        lp = new LinearLayout.LayoutParams(160, 160);
        lp.setMargins(5, 5, 5, 5);
        roundLayout2.addView(roundProgressBar5, lp);

        roundProgressBar6 = new RoundProgressBar(this);
        roundProgressBar6.setStyle(RoundProgressBar.FILL);
        roundProgressBar6.setCircleProgressColor(0xffC2C2C2);
        roundProgressBar6.setRoundWidth(1);
        roundProgressBar6.setCircleColor(0xffff0000);
        lp = new LinearLayout.LayoutParams(160, 160);
        lp.setMargins(5, 5, 5, 5);
        roundLayout2.addView(roundProgressBar6, lp);

        roundProgressBar7 = new RoundProgressBar(this);
        lp = new LinearLayout.LayoutParams(160, 160);
        lp.setMargins(5, 5, 5, 5);
        roundLayout2.addView(roundProgressBar7, lp);

        lp = new LinearLayout.LayoutParams(-1, -1);
        setContentView(parent, lp);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        while(progress <= 100){
                            progress += 3;

                            System.out.println(progress);
                            roundProgressBar.setProgress(progress);
                            roundProgressBar2.setProgress(progress);
                            roundProgressBar3.setProgress(progress);
                            roundProgressBar4.setProgress(progress);
                            roundProgressBar5.setProgress(progress);
                            roundProgressBar6.setProgress(progress);
                            roundProgressBar7.setProgress(progress);

                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }

                    }
                }).start();
            }
        });
    }
}